import {injectable,inject} from "inversify"
import { PrismaDB } from "../../db"

@injectable()
export class UserService {
   // 自动注入prisma
   constructor(@inject(PrismaDB) private PrismaDB: PrismaDB) {}

   /**
    * 注册新用户
    */
   public async add(userName:string) {
     return await this.PrismaDB.prisma.user.create({
        data:{
           userName:userName
        }
     })
   }

   /**
    * 根据userName查询用户
    */
   public async getUserByUserName(userName:string) {
     return await this.PrismaDB.prisma.user.findFirst({
        where:{
           userName:userName
        }
     })
   }

   /**
    * 查询用户数量
    */
   public async getUserCount() {
     return await this.PrismaDB.prisma.user.count()
   }
}